if ("serviceWorker" in navigator) {
  // 检查当前浏览器是否支持 Service Workers
  navigator.serviceWorker
    .register("/sw.js") // 如果支持就注册一个 'sw.js' 的 Service Worker 文件
    .then((registration) => {
      console.log("ServiceWorker Registered successful:", registration.scope);
    })
    .catch((err) => {
      // 注册失败
      console.log("ServiceWorker Registered failed: ", err);
    });
}
